package com.woniuxy.rabbitmq;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.woniuxy.config.RabbitMqConfig;
import com.woniuxy.rabbitmq.sender.FirstSender;
import com.woniuxy.util.TimeUtils;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.HashMap;

/**
 * @author fengyao
 * @version 1.0
 * @date 2019/9/28 0028 下午 8:30
 */

@Component
public class RabbitMQSend {

    //
    @Resource
    FirstSender firstSender;

    /**
     * 通知goods模块
     * @param gid 获取商品id
     * @param time 时间参数
     */
    public void sendStart(Integer gid, Integer aid,Long time){
        HashMap<String, Object> stringObjectHashMap = new HashMap<>();
        stringObjectHashMap.put("gid",gid);
        stringObjectHashMap.put("aid",aid);
        String o = JSON.toJSONString(stringObjectHashMap);
        firstSender.sendDelayed(TimeUtils.getUUID(),
               o ,RabbitMqConfig.EXCHANGE_DELAYED,RabbitMqConfig.ROUTINGKEY_START,time);
    }

    /**
     * 通知auction模块结束竞拍
     * @param aid 获取商品id
     * @param time 时间参数
     */
    public void sendStop(Integer aid,Long time){
        HashMap<String, Object> stringObjectHashMap = new HashMap<>();
        stringObjectHashMap.put("aid",aid);
        String o = JSON.toJSONString(stringObjectHashMap);
        firstSender.sendDelayed(TimeUtils.getUUID(),
                o ,RabbitMqConfig.EXCHANGE_DELAYED,RabbitMqConfig.ROUTINGKEY_END,time);
    }

    /**
     *
     * @param aid 获取商品id
     * @param time 时间参数
     */
    public void sendCollect(Integer aid,Long time){
        HashMap<String, Object> stringObjectHashMap = new HashMap<>();
        stringObjectHashMap.put("aid",aid);
        String o = JSON.toJSONString(stringObjectHashMap);
        System.out.println(firstSender);
        firstSender.sendDelayed(TimeUtils.getUUID(),
                o ,RabbitMqConfig.EXCHANGE_DELAYED,RabbitMqConfig.ROUTINGKEY_COLLECT,time);
    }

}
